﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="productadd.aspx.cs" Inherits="UI.system.page.product.productadd" %>
<%@ Import Namespace="Model" %>
<%@ Import Namespace="Common" %>
<div style="margin: 15px;">
	<form class="layui-form" style="padding-left:0px;">
        <div class="layui-form-item">
			<label class="layui-form-label"><font>商品分类</font><em>*</em></label>
			<div class="layui-input-block">
                <div style="float:left; margin-right:10px;">
				<select id="category1id" name="category1id" lay-verify="required" lay-filter="category1id" style="width:200px;">
				</select>
                </div>
                <div style="float:left;">
                <select id="category2id" name="category2id" lay-verify="required" lay-filter="category2id" style="width:200px;">
				</select>
                </div>
			</div>
		</div>
        <div class="layui-form-item">
			<label class="layui-form-label"><font>商品编号</font><em>*</em></label>
			<div class="layui-input-block">
                <input type="text" name="num" placeholder="请输入商品编号" lay-verify="required" autocomplete="off" class="layui-input" value="<%=info.Num %>">
			</div>
		</div>
        <div class="layui-form-item">
			<label class="layui-form-label"><font>商品名称</font><em>*</em></label>
			<div class="layui-input-block">
                <input type="text" name="name" placeholder="请输入商品名称" lay-verify="required" autocomplete="off" class="layui-input" value="<%=info.Name %>">
			</div>
		</div>
        <div class="layui-form-item">
			<label class="layui-form-label"><font>商品图片</font><em>*</em></label>
			<div class="layui-input-block" lay-verify="img">
                <div id="img_panel" class="imgview">
                    <%if(info.Imgs.Length>0){
                      foreach(string img in info.Imgs){ 
                    %>
                        <div><img class="img" src="<%=img %>"/><div id="<%=img %>" class="delete" onclick="RemoveFile(this)"><img src="/system/img/delete.png"></div></div>
                    <%}} %>
                </div>
				<div id="upload_file_o"></div>
			</div>
		</div>
        <div class="layui-form-item">
			<label class="layui-form-label"><font>市场价</font><em>*</em></label>
			<div class="layui-input-block">
				<input type="text" name="oprice" placeholder="请输入市场价" lay-verify="required" autocomplete="off" class="layui-input" value='<%=info.OPrice %>'>
			</div>
		</div>
        <div class="layui-form-item">
			<label class="layui-form-label"><font>优惠价</font><em>*</em></label>
			<div class="layui-input-block">
				<input type="text" name="aprice" placeholder="请输入优惠价" lay-verify="required" autocomplete="off" class="layui-input" value='<%=info.APrice %>'>
			</div>
		</div>
        <div class="layui-form-item">
			<label class="layui-form-label"><font>产品标签</font><em>*</em></label>
			<div class="layui-input-block tags" style="padding-top:10px;">
                <%foreach(TagsInfo tags in tagslist){ %>
				<input type="checkbox" name="btns" lay-skin="primary" title="<%=tags.Name %>" value="<%=tags.ID %>" <%=info.Tags.Split(',').Contains(tags.ID.ToString())?"checked":"" %>>
                <%} %>
			</div>
		</div>
        <div class="layui-form-item">
			<label class="layui-form-label"><font>单位/规格</font><em>*</em></label>
			<div class="layui-input-block">
				<input type="text" name="unit" placeholder="请输入商品单位或规格" lay-verify="required" autocomplete="off" class="layui-input" value='<%=info.Unit %>'>
			</div>
		</div>
        <div class="layui-form-item">
			<label class="layui-form-label"><font>显示顺序</font><em>*</em></label>
			<div class="layui-input-block">
				<input type="text" name="sort" placeholder="请输入显示顺序" lay-verify="required" autocomplete="off" class="layui-input" value='<%=info.Sort %>'>
			</div>
		</div>
        <div class="layui-form-item">
			<label class="layui-form-label"><font>商品详情</font><em>*</em></label>
			<div class="layui-input-block" lay-verify="context">
                <script id="context" type="text/plain" style="width:100%;height:250px;"><%=info.Context %></script>
			</div>
		</div>
		<a lay-filter="save" lay-submit style="display: none;"></a>
	</form>
</div>
<script>
    var categorys = eval('<%=categorys %>');
    var category1id=<%=info.Category1ID%>;
    var category2id=<%=info.Category2ID%>;
    
    function Init_Category1() {
        var buffer=new StringBuffer();
        $.each(categorys,function(i,info){
            if(info.ParentID==0){
                buffer.append('<option value="'+info.ID+'" '+ (info.ID==category1id?"selected":"")+'>'+info.Name+'</option>');
            }
        });
        if(categorys.length==0){
            $("#category1id").html('<option value="0">暂无分类</option>');
        }else{
            $("#category1id").html(buffer.toString());
        }
        form.render("select");
    };
    function Init_Category2(parentid) {
        var buffer=new StringBuffer();
        $.each(categorys,function(i,info){
            if(info.ParentID==parentid){
                buffer.append('<option value="'+info.ID+'" '+ (info.ID==category2id?"selected":"")+'>'+info.Name+'</option>');
            }
        });
        if(buffer.toString()==""){
            $("#category2id").html('<option value="0">暂无分类</option>').parent().hide();
        }else{
            $("#category2id").html(buffer.toString()).parent().show();
        }
        form.render("select");
    };
    form.on("select(category1id)",function(){
        Init_Category2($("#category1id").val());
        form.render("category1id");
    });
    Init_Category1();
    Init_Category2($("#category1id").val());
</script>